package com.maimao.upload.client.fallback;

import com.maimao.core.enums.RespCode;
import com.maimao.core.model.resp.Result;
import com.maimao.model.user.sys.vo.Permissions;
import com.maimao.upload.client.BrandClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class BrandFallBackFactory implements FallbackFactory<BrandClient> {

    @Override
    public BrandClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new BrandClient() {
            @Override
            public Result<String> findLogoById(Integer id) {
                log.error("调用[BrandClient-findLogoById({})]出错 :{}", id, errorMsg);
                return Result.fail(RespCode.FAIL, errorMsg);
            }

            @Override
            public Result<Void> updateLogo(Map<String, String> data) {
                log.error("调用[BrandClient-updateLogo({})]出错 :{}", data, errorMsg);

                return Result.fail(RespCode.FAIL, errorMsg);
            }


        };
    }
}
